package com.example.mercury.login;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatButton;

import com.example.mercury.R;
import com.example.mercury.entity.User;
import com.example.mercury.utils.HttpUtils;
import com.google.gson.Gson;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * @author 盛守义
 * @createTime 2021/10/24 16:10
 * @projectName TurningCoffee
 * @className ResetPasswordActivity.java
 * @description TODO
 */
public class ResetPasswordActivity extends Activity {

    private EditText et_pwdagain, et_checkpwd;
    private AppCompatButton btn_submitagain;
    private String pwd, pwdagain, email;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setpwdagain);
        email = getIntent().getStringExtra("mail");
        initViews();
        setListener();
    }

    void initViews(){
        et_pwdagain = findViewById(R.id.et_pwdagain);
        et_checkpwd = findViewById(R.id.lg_truepwdagain);
        btn_submitagain = findViewById(R.id.btn_submitagain);
    }

    class MyOnClickLiastener implements View.OnClickListener{

        @Override
        public void onClick(View view) {
            initValue();
            if(!pwd.equals(pwdagain)){
                Toast.makeText(getApplicationContext(), "两次密码输入不一致", Toast.LENGTH_SHORT).show();
            }else{
                Gson gson = new Gson();
                User user = new User();
                user.setUserTel(email);
                user.setUserPassword(pwd);
                String jsonSrting = gson.toJson(user);

                HttpUtils httpUtils = new HttpUtils();
                RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=utf-8"), jsonSrting);
                //发送

                //判断后finish

            }
        }
    }

    void setListener(){
        btn_submitagain.setOnClickListener(new MyOnClickLiastener());
    }

    void initValue(){
        pwd = et_pwdagain.getText().toString().trim();
        pwdagain = et_checkpwd.getText().toString().trim();
    }
}
